<?php

/**
 * $message_color: You can choose between blue, yellow and red
 */

function isNewPage($created_at)
{
    $created_timestamp = w4uUtil::getTimestamp($created_at);
    if ($created_timestamp <= time() && time() <= $created_timestamp + 604800)
        return true;
    return false;

}

function get_current_message($frontoffice = false)
{
    $expire_at = date('M d, Y',strtotime(sfContext::getInstance()->getUser()->getPage()->PagePlan->expires_at));

    switch (sfContext::getInstance()->getUser()->getPage()->State->state) {
		case 'install-job':
			$message_color = 'yellow';
			if ($frontoffice)
        $message_text = __("Tip of the day: Increase candidate traffic by %admin_section_link%.",
                array('%admin_section_link%' => link_to(__("launching targeted Facebook job ads", null, 'notifications'), fb_url_for('@backoffice_list', true), array('target' => '_top'))), 'notifications');
			else
				$message_text = __("Use our powerful advertising tool to automatically target the right candidates for your jobs. <br />".
								"Click on the <strong>Advertise your job</strong> button below.",
								null, 'notifications');
        break;

		case 'install-pause':
			$message_color = 'yellow';
			$message_text = __("All you jobs are paused (...)", null, 'notifications');
        break;

		case 'install-5d':
			$message_color = 'yellow';
			$message_text = __("Your free trial expires on <strong>%expire_at%</strong>. %subscription_link% now to keep using the app, starting at &#36;9 per month.",
							array(
								'%expire_at%' => $expire_at,
								'%subscription_link%' => link_to(__("Click here", null, 'notifications'),
																	fb_url_for('@backoffice_subscription', true),
																	array('target' => '_top')
																),
                            ), 'notifications');
			$dialog_title = __('Free trial expiring', null, 'notifications');
			$dialog_text =  __('Your free trial expires on %expire_at%. <strong>%click%</strong> now to keep using the app, starting at &#36;9 per month.', 
							array(
								'%expire_at%' => $expire_at,
								'%click%'     => link_to(__('Click here', null, 'notifications'), 
                                                        fb_url_for('@backoffice_subscription', true),
                                                        array('target' => '_top')
                                                       ),
								), 'notifications');
        break;


		case 'install-1d':
			$message_color = 'red';
			$message_text = __("Your free trial expires on <strong>%expire_at%</strong>. <strong>%subscription_link%</strong> now to keep using the app, starting at &#36;9 per month.",
							array(
								'%expire_at%' => $expire_at,
								'%subscription_link%' => link_to(__("Click here", null, 'notifications'),
																	fb_url_for('@backoffice_subscription', true),
																	array('target' => '_top')
																),
								), 'notifications');
			$dialog_title =  __('Free trial ending');
			$dialog_text =  __('Your free trial expires on <strong>%expire_at%</strong>. <strong>%click%</strong> now to keep using the app, starting at &#36;9 per month.',
							array(
								'%expire_at%' => $expire_at,
								'%click%'     => link_to(__('Click here', null, 'notifications'), 
															fb_url_for('@backoffice_subscription', true),
															array('target' => '_top')
														),
								), 'notifications');

        break;


		case 'free-upgrade':
			$message_color = 'red';
			$message_text = __("You have a Free plan and you can only have 1 job visible at a time. ".
							"%subscription_link% now to activate all your jobs, starting at &#36;9 per month.",
							array(
								'%subscription_link%' => link_to(__("Click here", null, 'notifications'),
																	fb_url_for('@backoffice_subscription', true),
																	array('target' => '_top')
																),
								), 'notifications');
			$dialog_title =  __('Free trial period is over');
			$dialog_text =  __('You have a Free plan and you can only have 1 job visible at a time. <strong>%click%</strong> now to activate all your jobs, starting at &#36;9 per month.', 
								array('%click%' => link_to(__("Click here", null, 'notifications'),
															fb_url_for('@backoffice_subscription'),
															array('target' => '_top')
													)
								), 'notifications');
        break;

		
		case 'plan-full':
			$message_color = 'yellow';
			$message_text = __("You have used all your job slots and cannot post additional jobs. ".
							"%subscription_link% now to upgrade your existing plan.",
							array(
								'%subscription_link%' => link_to(__("Click here", null, 'notifications'),
																	fb_url_for('@backoffice_subscription', true),
																	array('target' => '_top')
																),
								), 'notifications');	
        break;


		case 'plan-upgrade':
			$message_color = 'yellow';
			$message_text = __("You cannot activate more jobs with your current plan. ".
							"%subscription_link% now to upgrade your existing plan and activate all your jobs.",
							array(
								'%subscription_link%' => link_to(__("Click here", null, 'notifications'),
																	fb_url_for('@backoffice_subscription', true),
																	array('target' => '_top')
																),
								), 'notifications');
			$dialog_title =  __('Upgrade your plan');
			$dialog_text =  __('You cannot activate more jobs with your current plan. <strong>%click%</strong> now to upgrade your existing plan and activate all your jobs.',
							array(
								'%click%' => link_to(__("Click here", null, 'notifications'),
														fb_url_for('@backoffice_subscription'),
														array('target' => '_top')
													),
								), 'notifications');
        break;

		
		case 'plan-expired':
			$message_color = 'yellow';
			$message_text = __("We did not receive the payment of your monthly plan. All your jobs are now inactive. ".
							   "Update your payment information by %subscription_link%.",
							   array(
								   '%subscription_link%' => link_to(__("clicking here", null, 'notifications'),
																	fb_url_for('@backoffice_subscription', true),
																	array('target' => '_top')
																   ),
								   ), 'notifications');

        break;

		default:
			$message_color = 'yellow';
            if (rand (1, 2) == 2)
				$message_text = __("Tip of the day: Reach additional candidates by %link%.",
									array(
                                        '%link%' => link_to(__("tweeting your jobs automatically", null, 'notifications'),
                                                        fb_url_for('@backoffice_settings?tweet=true', true),
														array('target' => '_top')
														),
										), 'notifications');	
            else
				$message_text = __("Tip of the day: Build a talent community by %link%.",
								   array(
                                        '%link%' => link_to(__("auto-posting jobs to your Page's wall", null, 'notifications'),
															fb_url_for('@backoffice_settings?post=true', true),
															array('target' => '_top')
															),
										), 'notifications');
    }

    $res = '';

    if (!empty($dialog_title) && !empty($dialog_text)) {
        $res .= '<div id="state_dialog_title" style="display : none">'.$dialog_title.'</div>'."\n";
        $res .= '<div id="state_dialog_text" style="display : none">'.$dialog_text.'</div>'."\n";
    }

    $imports = sfContext::getInstance()->getUser()->getPage()->Imports;

    if (!$imports->isNew() && $imports->is_active && $imports->is_first_import) {
                $message_color = 'yellow';
                $message_text = __('Your jobs are being imported and will be ready in a few minutes.');
    }

    if ($frontoffice
        && sfContext::getInstance()->getRequest()->getParameter('is_tabbed')
        && (int) sfContext::getInstance()->getUser()->getPage()->Profile->current_api_id
        && App::getCurrentApiId() !== (int) sfContext::getInstance()->getUser()->getPage()->Profile->current_api_id) {
        $message_color = 'red';
        $tooltip = w4l_link_to_tooltip('<i class="FB_icons icon_help"></i>',__('On the tabs menu on the left, click "edit", then click the "x" icon on the right of your old tab.'), '', array(), 'bottom');
        $message_text = '
            <h2 class="mt05">'.__('You\'re still using your old Tab.').'</h2>
            <p>
            '.__('Please %delete_your_old_tab% before installing the new one.', array('%delete_your_old_tab%' =>__('delete your old Tab').'&nbsp;'.$tooltip)).'
            </p>';
    }

    if (!empty($message_color) && !empty($message_text)) {
        $res .= '<div class="message-'.$message_color.'">'."\n";
        $res .= $message_text."\n";
        $res .= '</div>'."\n";
    }

    return $res;
}

?>
